function createLine(data){
				for(var i=0;i<data.content.length;i++){
					var tab=document.getElementById("tab")
					var tr=document.createElement("tr")

					var td=document.createElement("td")
					var span=document.createElement("span")
					span.setAttribute("data",JSON.stringify(data.content[i]))
					span.className="glyphicon glyphicon-unchecked"
					span.style.cursor="pointer"
					span.setAttribute("_id",data.content[i].id)
					span.setAttribute("consumption",data.content[i].consumption)
					if(data.content[i].settled_fee==="已结算"){
						var span=document.createElement("p")
						span.textContent="已结算"
					}
					else{
						td.appendChild(span)
					}
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].member
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].number
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].vehicle
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].site
					tr.appendChild(td)


					var td=document.createElement("td")
					td.textContent=data.content[i].date
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].consumption
					tr.appendChild(td)


					var td=document.createElement("td")
					td.textContent=data.content[i].oil
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].capacity.toFixed(2)
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].operator
					tr.appendChild(td)

					var td=document.createElement("td")
					var btn=document.createElement("button")
					var status=data.content[i].settled_fee
					btn.textContent=status
					if (status==="未结算"){
						btn.className="btn btn-xs btn-danger"
					}
					else if (status==="预结算"){
						btn.className="btn btn-xs btn-primary"
					}
					else{
						btn.className="btn btn-xs btn-success"
					}
					td.appendChild(btn)
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].settled_date
					tr.appendChild(td)

					tab.appendChild(tr)
			}
}
document.getElementById("q1").onclick=function(){
	var data={}
	data["username"]=getQ().username
	data.start_date=$("#start_date").val()
	data.end_date=$("#end_date").val()
	if(data.start_date===""){
		showErrorInfo("请您选择起始日期进行查询！")
		return false;
	}
	if (data.end_date===""){
		showErrorInfo("请您选择终止日期进行查询！")
		return false;
	}
	data.bill_type=$("#bill_type").val()
	query(data)

}
function query(data){
	$("#tab>tr").remove()
	data=JSON.stringify(data)
	$.ajax({
		"url":"/settle/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"data":{"data":data},
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				createLine(data)
				if(data.user_type==="财务"){
					$("#recv").css({"display":"block"})
				}
				else{
					$("#recv").css({"display":"none"})
				}
			}
		}
	})
}
document.getElementById("reset").onclick=function(){
	$("#tab>tr").remove()
	$("#start_date").val("")
	$("#end_date").val("")
	$("#bill_type").val("全部")
}
document.getElementById("print").onclick=function(){
	window.data=[]
	$("tbody .glyphicon-check").each(function(){
		var _id= $(this).attr("_id")
		var x=JSON.parse($(this).attr("data"))
		window.data.push(x)
	})
	if(window.data.length===0){
		showErrorInfo("当前没有选中账单！")
		return false;
	}
	console.log(window.data)
	window.open ("billPrint.html", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
}
document.getElementById("selectAll").onclick=function(){
	if($(this).hasClass("glyphicon-unchecked")){
		$("table span").removeClass("glyphicon-unchecked").addClass("glyphicon-check")
	}
	else{
		$("table span").removeClass("glyphicon-check").addClass("glyphicon-unchecked")
	}
	var b=0
	$("tbody .glyphicon-check").each(function(){
		var _b=$(this).attr("consumption")
		_b=parseFloat(_b)
		b+=_b
	})
	$("#title").text("当前已选中金额为: "+b.toFixed(2) +"元")
}
document.getElementById("recv").onclick=function(){
	var unsettled_list=[]
	var data=[]
	$("tbody .glyphicon-check").each(function(){
		var _id=$(this).attr("_id")
		var _data=$(this).attr("consumption")
		_data=parseFloat(_data)
		unsettled_list.push(_id)
		data.push(_data)
	})
	if(unsettled_list.length===0){
		showErrorInfo("您当前还没有选中要结算的条目！")
		return false;
	}
	var number=getQ().number
	
	var banance=0
	for(var i=0;i<data.length;i++){
		banance+=data[i]
	}
	unsettled_list=JSON.stringify(unsettled_list)
						t=confirm("您确认收到了 "+number+" 的 "+banance+" 元欠款了吗？")
						if(!t){
							showErrorInfo("您已取消操作！")
							return false;
						}
						$.ajax({
							"url":"/settle/",
							"type":"POST",
							"error":errorAjax,
							"complete":stop_load_pic,
							"beforeSend":start_load_pic,
							"data":{"data":unsettled_list},
							"success":function(data){
								if(responseCheck(data)){
									alert("收款成功！")
									window.location.reload()
								}
							}
						})
}
$(document).on("click","tbody span",function(){
	if($(this).hasClass("glyphicon-unchecked")){
		$(this).removeClass("glyphicon-unchecked").addClass("glyphicon-check")
	}
	else{
		$(this).removeClass("glyphicon-check").addClass("glyphicon-unchecked")
	}
	var b=0
	$("tbody .glyphicon-check").each(function(){
		var _b=$(this).attr("consumption")
		_b=parseFloat(_b)
		b+=_b
	})
	$("#title").text("当前已选中金额为: "+b.toFixed(2) +"元")
})
